package cn.edu.scau.cmi.xiaozecheng.integration;

import cn.edu.scau.cmi.xiaozecheng.client.AbstractFactoryClient;
import cn.edu.scau.cmi.xiaozecheng.client.AdapterClient;
import cn.edu.scau.cmi.xiaozecheng.client.ConsistentCompositeClient;
import cn.edu.scau.cmi.xiaozecheng.client.FactoryClient;
import cn.edu.scau.cmi.xiaozecheng.client.HibernateClient;
import cn.edu.scau.cmi.xiaozecheng.client.SafeCompositeClient;
import cn.edu.scau.cmi.xiaozecheng.client.SimpleFactoryMethodClient;
import cn.edu.scau.cmi.xiaozecheng.client.SingletonClient;
import cn.edu.scau.cmi.xiaozecheng.client.SpringClient;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Intergration extends Application {

	public void initSet() {
		setAction();
	}

	Button button1 = new Button("单例模式+多例模式");
	// Button button2 = new Button("多例模式");
	Button button3 = new Button("简单工厂模式");
	Button button4 = new Button("工厂方法模式");
	Button button5 = new Button("抽象工厂模式");
	Button button6 = new Button("(类和对象)适配器模式");
	Button button7 = new Button("安全组合模式");
	Button button8 = new Button("一致性组合模式");
	Button button9 = new Button("Hibernate框架");
	Button button10 = new Button("Hibernate+Spring");

	@Override
	public void start(Stage primaryStage) throws Exception {
		try {
			initSet();
			primaryStage.setTitle("综合性实验");
			primaryStage.getIcons()
					.add(new Image(Thread.currentThread().getContextClassLoader().getResourceAsStream("scau.jpg")));

			Label label = new Label("       这是R6肖泽铖201727010623的综合性实验             ");
			VBox vBox = new VBox();

			button1.setPrefSize(200, 50);
			//button2.setPrefSize(200, 50);
			button3.setPrefSize(200, 50);
			button4.setPrefSize(200, 50);
			button5.setPrefSize(200, 50);
			button6.setPrefSize(200, 50);
			button7.setPrefSize(200, 50);
			button8.setPrefSize(200, 50);
			button9.setPrefSize(200, 50);
			button10.setPrefSize(200, 50);

			vBox.getChildren().addAll(label, button1, /* button2, */ button3, button4, button5, button6, button7,
					button8, button9, button10);
			vBox.setAlignment(Pos.CENTER);
			Scene scene = new Scene(vBox, 300, 400);

			primaryStage.setScene(scene);

			primaryStage.show();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		launch(args);
	}

	public void setAction() {
		// 单例模式+多例模式
		button1.setOnAction(e -> {
			try {
				new SingletonClient().start(new Stage());
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			;
		});
		// 简单工厂模式
		button3.setOnAction(e -> {
			try {

				new SimpleFactoryMethodClient().start(new Stage());
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			;
		});
		// 工厂方法模式
		button4.setOnAction(e -> {
			try {
				new FactoryClient().start(new Stage());
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			;
		});
		// 抽象工厂模式
		button5.setOnAction(e -> {
			try {
				new AbstractFactoryClient().start(new Stage());
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			;
		});
		// 适配器模式
		button6.setOnAction(e -> {
			try {
				new AdapterClient().start(new Stage());
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			;
		});
		// 安全组合模式
		button7.setOnAction(e -> {
			try {
				new SafeCompositeClient().start(new Stage());
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			;
		});
		// 一致性组合模式
		button8.setOnAction(e -> {
			try {
				new ConsistentCompositeClient().start(new Stage());
			} catch (Exception e1) {
				e1.printStackTrace();
			}
			;
		});
		// Hibernate框架
		button9.setOnAction(e -> {
			try {
				new HibernateClient().start(new Stage());
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		});
		// Hibernate+Spring
		button10.setOnAction(e -> {
			try {
				new SpringClient().start(new Stage());
			} catch (Exception e3) {
				e3.printStackTrace();
			}
		});

	}
}
